Page({
  data: {
    username: '',
    password: '',
  },

  // 获取输入用户名  
  usernameInput: function (e) {
    this.setData({
      username: e.detail.value
    })
  },

  // 获取输入密码  
  passwordInput: function (e) {
    this.setData({
      password: e.detail.value
    })
  },

  // 登录  
  login: function () {
    var that = this;
    if (this.data.username.length == 0 || this.data.password.length == 0) {
      wx.showToast({
        title: '框框不能为空',
        icon: 'loading',
        duration: 2000
      })
    } else {
      wx.request({
        url: getApp().globalData.ADMIN_API_HOST+"/login",
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method: "POST",
        data: { account: this.data.username, password: this.data.password },
        fail: function () {
          wx.showToast({
            title: '网络请求失败',
            icon: 'loading',
            duration: 2000
          })
        },
        success: function (res) {
          if(res.data.isSuccess){
            getApp().inLoginWithData(res.data.customer);
            wx.showToast({
              title: '登录成功',
              icon: 'success',
              duration: 2000
            });
            wx.switchTab({
              url: '../mine/mine',
              success: function (e) {
                var page = getCurrentPages().pop();
                if (page == undefined || page == null) return;
                page.onShow();
              }
            })
          }else{
            wx.showToast({
              title: res.data.msg,
              icon: 'loading',
              duration: 2000
            });
          }
        }
      })
    }
  },

  register:function(){
    wx.navigateTo({
      url: '../register/register',
    })
  }

})   